/**
 * 
 */
package com.metagurukul.metaspace.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 * @author himanshu
 * 
 */
public class ChangePasswordForm extends ActionForm {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String oldPassword;
	private String newPassword;
	private String confirmPassword;

	/**
	 * @return the oldPassword
	 */
	public String getOldPassword() {
		return oldPassword;
	}

	/**
	 * @return the newPassword
	 */
	public String getNewPassword() {
		return newPassword;
	}

	/**
	 * @return the confirmPassword
	 */
	public String getConfirmPassword() {
		return confirmPassword;
	}

	/**
	 * @param oldPassword
	 *            the oldPassword to set
	 */
	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}

	/**
	 * @param newPassword
	 *            the newPassword to set
	 */
	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}

	/**
	 * @param confirmPassword
	 *            the confirmPassword to set
	 */
	public void setConfirmPassword(String confirmPassword) {
		this.confirmPassword = confirmPassword;
	}

	/**
	 * 
	 */
	public ChangePasswordForm() {
		super();
	}

	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		if (oldPassword == null || oldPassword.equals("")) {
			errors.add("oldPassword", new ActionMessage("error.oldPassword.required"));
		}
		if (newPassword == null || newPassword.equals("")) {
			errors.add("newPassword", new ActionMessage("error.newPassword.required"));
		}
		if (!newPassword.equals(confirmPassword)) {
			errors.add("confirmPassword", new ActionMessage("error.password.mismatch"));
		}
		return errors;
	}

	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		newPassword = null;
		oldPassword = null;
		confirmPassword = null;
	}

}
